import tornado.web
import tornado.ioloop
import sys
import threading

from tornado.options import options as tr_options
from tornado.options import define

from routers import APIs
import dataBase.dataBase


# 绑定基本信息
define("port", default=3000, help="port", type=int)



# 声明版本判断函数
def checkVersion():
    # 检测 Python 版本
    if (sys.version_info > (3, 8)): # tornado 监听事件策略调整
        from asyncio import set_event_loop_policy, WindowsSelectorEventLoopPolicy
        set_event_loop_policy(WindowsSelectorEventLoopPolicy())
        print("当前 Python 属性为" + sys.version + "，已调整 Tornado 监听策略")



# 声明主函数
def main():
    checkVersion()
    tr_options.parse_command_line()
    app = tornado.web.Application([
        (r'/api.*', APIs)
    ], debug=True)
    httpServer = tornado.web.HTTPServer(app)
    httpServer.listen(tr_options.port)
    tornado.ioloop.IOLoop.current().start()



if __name__ == "__main__":
    main()